/**
 * Created by Administrator on 2017/8/9 0009.
 */
var jifangFormatter = function(value,row,index){
    return ['<a href="javascript:void(0)" class="xjjilu">巡检记录</a>'+'&nbsp&nbsp&nbsp'+'<a href="javascript:void(0)" class="gzjilu">故障记录</a>'].join('');
}

var stateFormatter = function(value,row,index){

    if(value==1){
        return ['<a href="javascript:void(0)">正常</a>'].join('');
    }else if(value==0){
        return ['<a href="javascript:void(0)" style="color:red">维修</a>'].join();
    }

}

window.jifangEvents={
    'click .xjjilu':function(e,value,row,index){

        showModel("xjjilu-div");
        var url = $().AbsUrlParse("/web/inspection/xjjilu?id="+value);
        $("#xjtable").bootstrapTable("refresh",{url:url});

    },
    'click .gzjilu':function(e,value,row,index){
        showModel("gzjilu-div");
        var url = $().AbsUrlParse("/web/inspection/gzjilu?id="+value);
        $("#gztable").bootstrapTable("refresh",{url:url});
    }
}


bindClick("#xjSearBtn",function(){
    //得到查询的信息
    var xjtimeSear = $("input[name=xjtimeSear]").val();
    var xjstart = "", xjend = "";
    if (xjtimeSear != null) {
        xjstart = xjtimeSear.split(" - ")[0];
        xjend = xjtimeSear.split(" - ")[1];
    }


    var wName = $("select[name=wName]").val();
    var xjcycleSear = $("select[name=xjcycleSear]").val();
    var xjmachnameSear = $("input[name=xjmachnameSear]").val();

    var url=$().AbsUrlParse("/web/motoroom/jifangQuery?xjstart="+xjstart+"&xjend="+xjend+"&wName="+wName+"&xjcycleSear="+xjcycleSear+"&xjmachnameSear="+xjmachnameSear);
    $("#table").bootstrapTable("refresh",{url:url});

});


$.post($().AbsUrlParse("/web/motoroom/xjPositionSelect"),{

},function(data){


    var datas = data.res.data;
    var selects = "<select class='form-control' name='wName'><option value=''>请输入位置</option>";
    for(var i=0;i<datas.length;i++){
        var val = datas[i].wName;
        selects+= "<option name="+val+">"+val+"</option>"
    }
    selects+="</select>"
    $("#postionSelect").html(selects);
});



//初始化页面的时候运行该函数
$(function () {
    initDateRange();
});

function initDateRange() {
    $(".rangedate").daterangepicker({
        "autoApply": true,
        "locale": {
            "applyLabel": "确定",
            "cancelLabel": "取消",
            "fromLabel": "开始",
            "toLabel": "结束",
            "customRangeLabel": "Custom",
            "weekLabel": "周",
            "daysOfWeek": [
                "日",
                "一",
                "二",
                "三",
                "四",
                "五",
                "六"
            ],
            "monthNames": [
                "1月",
                "2月",
                "3月",
                "4月",
                "5月",
                "6月",
                "7月",
                "8月",
                "9月",
                "10月",
                "11月",
                "12月"
            ],
            "cancelLabel": '清空',
            "opens": "right"
        },
        "format": "YYYY-MM-DD"
    }).on('cancel.daterangepicker', function (ev, picker) {
        $(this).val('');
    });
}
//***********************************
var loadTree = function (ids) {
    //加载tree
    var url = $().AbsUrlParse("/web/roleResource/loadResourceTree?ids=" + ids);
    var nodes ;
    var setting = {
        callback: {
            beforeClick: function beforeClick(treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj(treeId);
                zTree.checkNode(treeNode, !treeNode.checked, null, true);
                return true;
            },
            beforeCheck: zTreeBeforeCheck
        },
        check: {
            enable: true,
            chkboxType: {"Y": "p", "N": "ps"},
            chkStyle: "checkbox",
            radioType: "all"
        },
        async: {
            enable: true,
            url: function () {
                return url;
            },
            dataFilter: function (treeId, parentNode, childNodes) {
                $.unblockUI();
                //js中节点数据：
                return childNodes.res.data;
            }
        }
    };

    nodes = [
        //父节点展开 折叠时分别使用不同的图标
        { name:"", iconOpen:$().AbsUrlParse("/static/images/favicon.ico"), iconClose:$().AbsUrlParse("/static/images/favicon.ico")},
        //叶子节点个性化图标
        { name:"", icon:$().AbsUrlParse("/static/images/favicon.ico")}
    ]

    var zTree = $.fn.zTree.init($("ul[data-event=jstree_demo_div]"), setting);
    function zTreeBeforeCheck(treeId, treeNode) {
        //$("input[name=typeId]").val(treeNode.id);
    }
}

loadTree();